import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/controller/cache.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/models/student/AssignmentDetail.dart';
import 'package:ichinesereader/models/student/assignmentSearchDto.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/grids/homeworkOngoingDatagrid.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';

enum StatusOptions { OPEN, CLOSED }

// ignore: must_be_immutable
class TeacherReportsHomework extends StatefulWidget {
  TeacherReportsHomework({Key? key, required this.showAppbar}) : super(key: key);
  bool showAppbar;
  static const String routeName = '/teacher/reports/homework';

  @override
  _TeacherReportsHomework createState() => _TeacherReportsHomework();
}

class _TeacherReportsHomework extends State<TeacherReportsHomework> {
  final ReportsController _reportsController = Get.put(ReportsController());
  final box = Hive.box('appconfig');

  List<String> content = [];
  List<String> status = [];
  AssignmentSearchDto dto = AssignmentSearchDto();
  String classId = '';

  @override
  void initState() {
    classId = box.get(CacheManagerKey['currentclass'].toString());
    Future.delayed(Duration(milliseconds: 100), (() {
      dto.assignmentType = 'ASSIGNMENT';
      dto.past = true;
      dto.live = true;
      dto.sortField = "-created";
      _reportsController.fetchClassAssignmentsData(classId, dto);
    }));
    super.initState();
  }

  void fetchData(classId, dto) {
    _reportsController.fetchClassAssignmentsData(classId, dto);
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build teacher report homework progress');

    return Scaffold(
        backgroundColor: Colors.transparent,
         appBar: widget.showAppbar ? CustomAppBar(title: 'Homework Report'.tr) : null,
        body: Column(
          children: [
            Expanded(
              child: _reportsController.obx(
                (data) => HomeworkOngoingDataGrid(
                  true,
                  _reportsController.classassignmentsresult.value.list
                      as List<AssignmentDetail>,
                ),
                onEmpty: HomeworkOngoingDataGrid(
                  true,
                  [],
                ),
                onLoading: Container(),
              ),
            )
          ],
        ));
  }
}
